
function []=PlotDiffs2(colNames, dataTable, analyte1, analyte2)


analyteList = dataTable(:,1);
indX= find(analyteList == analyte1);
indY= find(analyteList == analyte2);

params1=dataTable(indX,4:end);
params2=dataTable(indY,4:end);

clusterList = dataTable(indX,3);
[~, clusterIDX1, ~]=  unique(clusterList);

clusterList = dataTable(indY,3);
[~, clusterIDX2, ~]=  unique(clusterList);

colNames=colNames(4:end);
selected=(1:size(params1,2))';

cc=1;
for I=1:length(selected)
    for J=I+1:length(selected)
        try
            V1x=params1(:,selected(I));
            V1y=params1(:,selected(J));
            V2x=params2(:,selected(I));
            V2y=params2(:,selected(J));
            
            %if one of the parameters is a cluster, then only plot the
            %unique values
            if isempty( strfind( colNames{selected(I)}, 'C_') ) ==false ...
                    || isempty( strfind( colNames{selected(J)}, 'C_') ) ==false
                V1x = V1x(clusterIDX1,:);
                V1y = V1y(clusterIDX1,:);
                
                V2x = V2x(clusterIDX2,:);
                V2y = V2y(clusterIDX2,:);
            end
            
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            % do a little normalization
            joinX= vertcat(V1x(:), V2x(:));
            joinY= vertcat(V1y(:), V2y(:));
            joinX(abs(joinX)>2)=[];
            joinY(abs(joinY)>2)=[];
            
            mX=mean(joinX);
            sX=sum(abs(joinX-mX))/length(joinX);
            
            mY=mean(joinY);
            sY=sum(abs(joinY-mY))/length(joinY);
            
%             clear joinX
%             clear joinY
            
            mnX=mX-sX;
            mxX=mX+sX;
            
            mnY=mY-sY;
            mxY=mY+sY;
            %
%             mnX=max([ mnX min(V1x) min(V2x)]);
%             mxX=min([ mxX max(V1x) max(V2x)]);
%             
%             mnY=max([ mnY min(V1y) min(V2y)]);
%             mxY=min([ mxY max(V1y) max(V2y)]);
            
            V1x=(V1x-mnX)/(mxX-mnX);
            V2x=(V2x-mnX)/(mxX-mnX);
            
            V1y=(V1y-mnY)/(mxY-mnY);
            V2y=(V2y-mnY)/(mxY-mnY);
            
            %put all the numbers into a pixel grid for plotting
            sizeI=500;
            ypred1 =zeros([sizeI,sizeI]);
            ypred2 =zeros([sizeI,sizeI]);
            
            idxX=round(V1x*sizeI);
            idxY=round(V1y*sizeI);
            idxX(idxX>sizeI)=sizeI;
            idxY(idxY>sizeI)=sizeI;
            idxX(idxX<1)=sizeI;
            idxY(idxY<1)=sizeI;
            
            pCount =0;
            for K=1:length(idxX)
                if idxX(K)~=sizeI && idxY(K)~=sizeI
                    ypred1(idxX(K),idxY(K))=ypred1(idxX(K),idxY(K))+1;
                    pCount=pCount+1;
                end
            end
            
            idxX=round(V2x*sizeI);
            idxY=round(V2y*sizeI);
            idxX(idxX>sizeI)=sizeI;
            idxY(idxY>sizeI)=sizeI;
            idxX(idxX<1)=sizeI;
            idxY(idxY<1)=sizeI;
            
            for K=1:length(idxX)
                if idxX(K)~=sizeI && idxY(K)~=sizeI
                    ypred2(idxX(K),idxY(K))=ypred2(idxX(K),idxY(K))+1;
                    pCount=pCount+1;
                end
            end
            
            
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            % now take the matrix and blur the values to give it a little
            % bit of a histogram feel (the same effect can be produced by
            % just reducing the number of pixels on the image)
            h = fspecial('gaussian', 111, 13);
            ypred1=imfilter(ypred1,h);
            ypred2=imfilter(ypred2,h);
            
            
            ypred1=1000*ypred1/(sum(ypred1(:)));
            ypred2=1000*ypred2/(sum(ypred2(:)));
            
            im=zeros([size(ypred1,1) size(ypred1,2) 3]);
            im(:,:,1)=ypred1;
            im(:,:,2)=ypred2;
            imM=max(im,[],3);
            
            %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
            % now calculate the probability by finding which one is the
            % max, and dividing by the sum of the two
            
            denom= (ypred1+ypred2);
            accurMap = ( imM );
            totalAccur=sum( accurMap(:) ) / sum(denom(:)) *100
            drawnow;
        %    figure(1);surf(accurMap);shading interp;
        %    figure(2);surf(denom);shading interp;
            %             figure(3);surf(ypred1);shading interp;
            %             figure(4);surf(ypred2);shading interp;
            
            %             denom=1;
            %             totalAccur = sum( sum( (accurMap.*denom))) / sum(denom(:)) *100
            
            if (totalAccur>60)
                
                %normalize the values from 0 to 255, and do the square root
                %for visibility
                ypred1=  (ypred1-min(ypred1(:)) ).^1;
                ypred1=round(  (ypred1/(max(ypred1(:))))*254);
                %
                ypred2= ( ypred2-min(ypred2(:))  ).^1;
                ypred2=round( (ypred2/(max(ypred2(:))))*254);
                %
                
                % make a nice image
                im=uint8(zeros([size(ypred1,1) size(ypred1,2) 3]));
                im(:,:,1)=round(ypred1);
                im(:,:,2)=round(ypred2);
                
                
                figure(1);
                imshow(im);
                title([colNames{selected(I)} ' '  colNames{selected(J)}]);
                drawnow;
                
                saveas(1,[ 'C:\temp\2D hist\A' num2str(totalAccur) '_' ...
                    colNames{selected(I)} '-'  colNames{selected(J)} '-' num2str(I) '_' num2str(J) '_' num2str(pCount) '.png']);
                disp('=====');
                cc=cc+1;
               
            end
            
        catch mex
            disp(mex)
            
        end
    end
  
end


